package com.xzyframework.security.uitls;

import com.xzyframework.SpringContextHolder;
import com.xzyframework.security.PasswordProcesser;

/**
 * 密码工具类
 * 
 * @author macong
 * @since 1.0
 * @version 2013-12-19 macong
 */
public class Passwords {
    
    /** FIXME */
    public static final String HASH_ALGORITHM = "SHA-1";
    
    /** FIXME */
    public static final int HASH_INTERATIONS = 128;
    
    /** FIXME */
    public static final int SALT_SIZE = 8;
    
    /** FIXME */
    private static PasswordProcesser passwordProcesser = SpringContextHolder.getBean(PasswordProcesser.class);
    
    /**
     * 生成安全的密码，生成随机的16位salt并经过128次 sha-1 hash
     * 
     * @param plainPassword 未加密密码
     * @return 加密后密码
     */
    public static String entryptPassword(String plainPassword) {
        return passwordProcesser.entryptPassword(plainPassword);
    }
    
    /**
     * 验证密码
     * 
     * @param plainPassword 明文密码
     * @param password 密文密码
     * @return 验证成功返回true
     */
    public static boolean validatePassword(String plainPassword, String password) {
        return passwordProcesser.validatePassword(plainPassword, password);
    }
}
